package com.example.demo2.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.demo2.dao.JsonReader;
import com.example.demo2.entity.Passenger;

public class BackToOrigin {
    static String path = JsonReader.class.getClassLoader().getResource("json/PassengerData.json").getPath();
    static String s = JsonReader.readJsonFile(path);
    static JSONObject passengerList = JSON.parseObject(s);
    static JSONArray passenger = passengerList.getJSONArray("Passenger");//构建JSONArray数组

    static String target = "<TextArea fx:id=\"text1\" layoutX=\"225.0\" layoutY=\"106.0\" prefHeight=\"157.0\" prefWidth=\"635.0\" text=\"";
    static String end = "\">";

    public static void back(){
        JSONObject object = null;
        for (int j = 0; j < passenger.size(); j++) {

            if (passenger.getJSONObject(j).getString("BookingNum").equals("111")) {
                object = passenger.getJSONObject(j);
            }
        }
        if (object!=null) {
            String departure = object.getString("departure");
            String Date = object.getString("Date");
            String departureTime = object.getString("departureTime");
            String duration = object.getString("duration");
            String arrivingTime = object.getString("arrivingTime");
            String theClass = object.getString("class");
            String destination = object.getString("destination");
            String text = departure + "——————————————" + destination + "&#10;" +"         "+
                    Date + "&#10;" +"        "+
                    departureTime +"——"+arrivingTime+ "&#10;" +"          "+
                    duration + "&#10;" +"         "+
                    "Class: " + theClass;
            System.out.println(text);
            ChangeWord.changeText(target + end, "src/main/resources/fxml/flight-info.fxml", target + text +end);
        }
    }
}
